$(function () {
    var s;
    var choose_file;
    $("#fileInput").change(function () {
        //拿到文件数据
        choose_file = $(this)[0].files[0];
        //截取图片名称小数点后的字符串
        var ftype = choose_file.name.substring(choose_file.name.lastIndexOf(".")+1);
        //校验格式是否是图片类型
        if(ftype=="jpg" || ftype=="png" || ftype=="jpeg" || ftype == "JPG"){
            //限制大小，照片大小不能超过1M
            var size = choose_file.size / 1024 / 1024;
            if (size > 1) {
                showNotification("top","提示","头像不能大于1M","warning");
                s = false;
            }
            // 实例化一个阅读器对象
            var reader = new FileReader();
            // 读取文件的路径，没有返回值,结果在reader.result里
            reader.readAsDataURL(choose_file);
            // 读取需要时间，读完后再修改图片路径
            reader.onload = function () {
                //回显给上方图片中
                $("#avatar_img").attr("src",this.result);
            }
        }else{
            showNotification("top","提示","头像格式不正确","warning");
            s = false;
        }
    });


    $("#imgUpload").on("click",function() {
        if (choose_file == null){
            showNotification("top","提示","请选则图片","warning")
        } else {
            $("#formUpload").submit()
        }
    });
});